<template>
  <div style="height: 435px" class="wrap">
	  <div>
<!--    <div v-loading="loading" element-loading-text="模型生成中..." :style="{ height: dynamicHeight }">-->
      <div :style="{ height: nodeDynamicHeight, marginTop: '10px'}">
        <div class="subTitle">BDF节点</div>
        <div style="height: 30px;line-height: 30px">
          <span class="letter">BDF风格</span>
          <el-radio-group size="small" style="margin-left: 10px" v-model="codeFormat">
            <el-radio size="small" label="format">小字段</el-radio>
            <el-radio size="small" label="lonfFormat">大字段</el-radio>
          </el-radio-group>
        </div>
        <div style="display: flex">
          <div class="letter" style="width: 68px;margin-top: 14px">节点文件</div>
          <div>
            <el-upload
                ref="uploadRef"
                class="upload-demo"
                :auto-upload="false"
                action=""
                :on-change="handleChange"
                :on-remove="handleRemove"
                :file-list="fileList"
                :limit="1"
                style="width: 150px;margin-left: 10px"
            >
              <div>
                <el-button size="small" type="primary">选择文件</el-button>
                <el-button type="primary" size="small" @click="generates">确定</el-button>
              </div>
            </el-upload>
          </div>
        </div>
      </div>
      <div :style="{ height: cellDynamicHeight, marginTop: '10px'}">
        <div class="subTitle">BDF单元</div>
        <div style="display: flex">
          <div class="letter">单元类型</div>
          <el-checkbox-group size="small" v-model="rootType" style="margin-left: 12px">
            <el-checkbox size="small" label="CBAR">CBAR</el-checkbox>
            <el-checkbox size="small" label="CTRIA3">CTRIA3</el-checkbox>
            <el-checkbox size="small" label="CQUAD4">CQUAD4</el-checkbox>
          </el-checkbox-group>
        </div>
        <div style="display: flex">
          <div class="letter" style="width: 68px;margin-top: 14px">是否修改</div>
          <el-radio-group size="small" v-model="isEdit" style="margin-left: 12px;margin-top: 14px" @change="changeEdit">
            <el-radio size="small" label="1">是</el-radio>
            <el-radio size="small" label="2">否</el-radio>
          </el-radio-group>
        </div>
        <div style="display: flex" v-if="isEdit== '1'">
          <div class="letter" style="margin-top: 14px">修改单元</div>
          <el-upload
              ref="uploadRef1"
              :auto-upload="false"
              action=""
              :on-change="handleChange1"
              :on-remove="handleRemove1"
              :file-list="fileList1"
              :limit="1"
              style="width: 195px;margin-left: 10px"
          >
            <el-button type="primary" size="small" @click.stop="bdfToExcelButton">导出单元文件</el-button>
            <el-button type="primary" size="small">选择文件</el-button>
          </el-upload>
        </div>
        <div style="display: flex">
          <div class="letter" style="margin-top: 14px">生成单元</div>
          <el-button  type="primary" size="small" @click.stop="generateUnit" style="margin-top: 10px; margin-left: 10px">生成单元</el-button>
        </div>
      </div>
      <div :style="{ height: checkDynamicHeight, marginTop: '10px'}">
        <div class="subTitle">辅助检查</div>
        <div style="display: flex">
          <div class="letter" style="width: 68px;margin-top: 14px">材料表格</div>
          <el-upload
              ref="uploadRef"
              :auto-upload="false"
              action=""
              :on-change="handleChange3"
              :on-remove="handleRemove3"
              :file-list="fileList3"
              :limit="1"
              style="width: 84px;margin-left: 10px"
          >
            <el-button size="small" type="primary">选择文件</el-button>
          </el-upload>
        </div>
        <div style="display: flex;">
          <div class="letter" style="width: 70px;margin-top: 14px">检查XML</div>
          <el-upload
              ref="uploadRef1"
              :auto-upload="false"
              action=""
              :on-change="handleChange2"
              :on-remove="handleRemove2"
              :file-list="fileList2"
              :limit="1"
              style="width: 150px;margin-left: 10px"
          >
            <el-button size="small" type="primary">选择文件</el-button>
            <el-button type="primary" size="small" @click="generates5">确定</el-button>
          </el-upload>
        </div>
      </div>
    </div>
    <div class="btn">
      <el-button type="primary" size="small"
                 @click="cancel">
	               取消
      </el-button>
    </div>
  </div>
</template>

<script>
import DialogMixin from "../DialogMixin";
import {compositeMaterialManageCommand} from "../../../command/CompositeMaterialManageCommand";
import {PluginFunctionType, Point} from "../../../../nodeApp/static/lib/crowncad-plugin-sdk-0.0.1";

export default {
  mixins: [DialogMixin],
  data() {
    return {
      loading: false,
      minHeight: 600,
      nodeDynamicHeight: '130px',
      cellDynamicHeight: '150px',
      checkDynamicHeight: '130px',
      dynamicHeight: '390px',
      fileList: [], // 文件列表
      file: null,   // 当前选中的文件
      allNode: null,
      rootType: [],
      codeFormat: 'format',
      fileList1: [], // 文件列表
      file1: null,   // 当前选中的文件
      isShowEdit: false,
      file2: null,
      file3: null,
      fourLineId: [],
      twoLineId:[],
      threeLineId:[],
      fileList2: [],
      fileList3: [],
      fibersimData: [],
      xmlData: [],
      plyData:{},
      plyDetail: [],
      newPly:[],
      isEdit: '2',
      result: [],
      pcompData:[],
      gridLine:[],
      entityFaces:{},
      lineNames:[],
      lineObject:{}
    }
  },

  mounted() {
    compositeMaterialManageCommand.init(330, 330, 485, () => {
      this.changePluginContainerHeight(0);
    });
  },

  methods: {
    cancel() {
      compositeMaterialManageCommand.closeActiveCmd();
    },

    changePluginContainerHeight(height) {
      compositeMaterialManageCommand.changePluginContainerHeight({
        minWidth: 485,
        maxHeight: 465 + height,
        width: 370
      });
    },

    // 增加对话框高度
    async addHeight() {
      this.minHeight = this.minHeight + 15;
      await compositeMaterialManageCommand.request.execFunction(PluginFunctionType.LAYOUT,
          {minWidth: 300, width: 300, maxHeight: this.minHeight});
    },

    // 减少对话框高度
    async minusHeight() {
      this.minHeight = this.minHeight - 15;
      await compositeMaterialManageCommand.request.execFunction(PluginFunctionType.LAYOUT, {
        minWidth: 300,
        width: 300,
        maxHeight: this.minHeight
      });
    },

    async handleChange(file) {
      this.file = file.raw; // 获取节点原始文件对象
      this.fileList = [file]; // 更新文件列表
      this.changeHeight();
      await this.handleUpload(); // 上传文件到后台
    },

    async handleRemove(file) {
      this.fileList = [];
      this.changeHeight();
    },

    changeEdit(value) {
      this.changeHeight();
    },

    async handleChange1(file) {
      this.file1 = file.raw; // 获取修改单元文件对象
      this.fileList1 = [file]; // 更新文件列表
      this.changeHeight();
      //await this.addHeight();
      await this.handleUpload1(); // 上传文件到后台
    },

    handleRemove1() {
      this.fileList1 = [];
      this.changeHeight();
    },

    async handleChange2(file) {
      this.file2 = file.raw; // 获取检查XML文件对象
      this.fileList2 = [file]; // 更新文件列表
      this.changeHeight();
      await this.handleUpload2(); // 上传文件到后台
    },

    handleRemove2() {
      this.fileList2 = [];
      this.changeHeight();
    },

    async handleChange3(file) {
      this.file3 = file.raw; // 获取原始文件对象
      this.fileList3 = [file]; // 更新文件列表
      this.changeHeight();
      await this.handleUpload3(); // 自动上传文件
    },

    handleRemove3() {
      this.fileList3 = [];
      this.changeHeight();
    },

    async handleUpload3() {
      if (!this.file3) {
        compositeMaterialManageCommand.eventBusAlertMsg("请先选择一个文件！", "error");
        return;
      }
      try {
        // 调用 uploadFile3 方法进行上传
        await this.uploadFile3(this.file3);
      } catch (error) {
        compositeMaterialManageCommand.eventBusAlertMsg("文件上传失败，请重试！", "error");
      }
    },

    async handleUpload2() {
      if (!this.file2) {
        compositeMaterialManageCommand.eventBusAlertMsg("请先选择一个文件！", "error");
        return;
      }
      try {
        // 调用 uploadFile2 方法进行上传
        await this.uploadFile2(this.file2);
      } catch (error) {
        compositeMaterialManageCommand.eventBusAlertMsg("文件上传失败，请重试！", "error");
      }
    },

    async handleUpload1() {
      if (!this.file1) {
        compositeMaterialManageCommand.eventBusAlertMsg("请先选择一个文件！", "error");
        return;
      }
      try {
        // 调用 uploadFile1 方法进行上传
        await this.uploadFile1(this.file1);
      } catch (error) {
        compositeMaterialManageCommand.eventBusAlertMsg("文件上传失败，请重试！", "error");
      }
    },

    // 手动上传按钮点击事件
    async handleUpload() {
      if (!this.file) {
        compositeMaterialManageCommand.eventBusAlertMsg("请先选择一个文件！", "error");
        return;
      }

      try {
        // 调用 uploadFile 方法进行上传
        await this.uploadFile(this.file);
      } catch (error) {
        compositeMaterialManageCommand.eventBusAlertMsg("文件上传失败，请重试！", "error");
      }
    },

    async generates(event) {
      // 阻止冒泡事件
      event.stopPropagation();
      if (!this.allNode?.GRID || this.allNode?.GRID?.length === 0) {
        compositeMaterialManageCommand.eventBusAlertMsg("未获取到节点文件数据，请检查！", "error");
        return;
      }
      compositeMaterialManageCommand.toolQuery.openLoading("正在生成节点，请稍候！");
      this.loading = true;
      compositeMaterialManageCommand.command.clearCommand();
      //绘制上翼面草图，命名为sketch1
      compositeMaterialManageCommand.command.sketch.create3DSketch({
        sketchName: "GRID",
      });
      // 遍历节点，根据几点钟x/y/z为0的情况分别在不同平面绘制节点
      for (let i = 0; i < this.allNode.GRID.length; i++) {
        // if (parseInt(this.allNode.GRID[i].z) === 0) {
        //   await this.createPoint(this.allNode.GRID[i].nodeId, 8, this.allNode.GRID[i].x, this.allNode.GRID[i].y);
        // } else if (parseInt(this.allNode.GRID[i].y) === 0) {
        //   await this.createPoint(this.allNode.GRID[i].nodeId, 36, this.allNode.GRID[i].x, this.allNode.GRID[i].z);
        // } else if (parseInt(this.allNode.GRID[i].x) === 0) {
        //   await this.createPoint(this.allNode.GRID[i].nodeId, 22, this.allNode.GRID[i].y, this.allNode.GRID[i].z);
        // } else {
        //   await this.create3DPoint(this.allNode.GRID[i]);
        // }
        //创建放样曲线
        let gridNode = this.allNode.GRID[i];
        let X = gridNode.x;
        let Y = gridNode.y;
        let Z = gridNode.z;
        compositeMaterialManageCommand.command.sketch.create3DPoint({X, Y, Z});
      }
      //退出草图
      compositeMaterialManageCommand.command.sketch.exitSketch();
      //实现草图操作，参数true会覆盖之前的草图，不传则不会
      await compositeMaterialManageCommand.command.execute();
      // console.log(this.allNode, 3)
      // 将所有数据传给后台处理，将直线数据CBAR、三角形数据CTRIA3以及四边形数据CQUAD4传给后台处理，并输出excel文件
      // await this.bdfToExcel(this.allNode)
      // this.isShowEdit= true
      this.loading = false;
      compositeMaterialManageCommand.toolQuery.closeLoading();
    },

    async bdfToExcelButton() {
      if (!this.rootType.length) {
        this.$message.error('请先选择一个单元类型');
        return;
      }
      let excelData= {CBAR :[], CTRIA3:[], CQUAD4:[]}
      if(this.rootType.includes('CBAR')) {
        excelData.CBAR= this.allNode.CBAR;
      }
      if(this.rootType.includes('CTRIA3')) {
        excelData.CTRIA3= this.allNode.CTRIA3;
      }
      if(this.rootType.includes('CQUAD4')) {
        excelData.CQUAD4= this.allNode.CQUAD4;
      }
      await this.bdfToExcel(excelData);
    },

    async generateUnit(event) {
      // 阻止冒泡事件
      event.stopPropagation();
      // if (!this.rootType.includes('CQUAD4') || !this.allNode?.CQUAD4) {
      //   let msg = "未获取到单元数据，请检查！"
      //   compositeMaterialManageCommand.eventBusAlertMsg(msg, "error");
      //   return;
      // }
      if (!this.rootType.length) {
        let msg = "请先选择一个单元类型"
        compositeMaterialManageCommand.eventBusAlertMsg(msg, "error");
        return;
      }
      this.loading = true;
      // 没有上传修改单元文件时，按照原始的数据进行生成四边形
      compositeMaterialManageCommand.toolQuery.openLoading("正在生成单元，请稍候！");
      if (this.rootType.includes('CQUAD4')) {
        if(this.fileList1.length) {
          // 将之前绘制的进行隐藏
          await this.setEntityVisible(this.fourLineId);
          await this.setEntityVisible(this.twoLineId);
          await this.setEntityVisible(this.threeLineId);
        }
        let featureNames = [];
        compositeMaterialManageCommand.command.clearCommand();
        for (let i = 0; i < this.allNode?.CQUAD4?.length; i++) {
          let lineId = this.allNode.CQUAD4[i].nodeId;
          let pointId = this.allNode.CQUAD4[i].n1;
          let point1Id = this.allNode.CQUAD4[i].n2;
          let point2Id = this.allNode.CQUAD4[i].n3;
          let point3Id = this.allNode.CQUAD4[i].n4;

          const point = this.allNode.GRID.find(item => item.nodeId === pointId);
          const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);
          const point2 = this.allNode.GRID.find(item => item.nodeId === point2Id);
          const point3 = this.allNode.GRID.find(item => item.nodeId === point3Id);
          let lId = lineId;
          if(this.fileList1.length) {
            lId = lineId +'new';
          }
          for (let j = 1; j < 5; j++) {
            featureNames.push(j + '四边形' + lId);
          }
          this.createCQUAD4(lId, point, point1, point2,point3);
        }

        await compositeMaterialManageCommand.command.execute();
        let res = await compositeMaterialManageCommand.query.getFeaturesByNames(featureNames);
        if (res && res.data && res.data.features?.length > 0) {
          res.data.features?.forEach(feature => {
            this.fourLineId.push(feature?.id)
            this.lineObject[feature.name]= feature?.id
          })
        }
        compositeMaterialManageCommand.command.clearCommand();
      }
      if(this.rootType.includes('CBAR') ) {
        let featureNames = [];
        compositeMaterialManageCommand.command.clearCommand();
        for (let i = 0; i <this.allNode?.CBAR?.length ; i++) {
          let lineId= this.allNode.CBAR[i].nodeId;
          let pointId= this.allNode.CBAR[i].n1;
          let point1Id= this.allNode.CBAR[i].n2;

          const point = this.allNode.GRID.find(item => item.nodeId === pointId);
          const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);

          let lId = lineId;
          if(this.fileList1.length) {
            lId = lineId +'new';
          }
          if(!this.lineNames.includes(1+ '直线' + lineId)) {
            compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
              pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
              isClosed: 0,
            },1+ '直线' + lineId)
            this.lineNames.push(1+ '直线' + lineId)
          }
          featureNames.push(1 + '直线' + lId);
        }
        await compositeMaterialManageCommand.command.execute();
        let res = await compositeMaterialManageCommand.query.getFeaturesByNames(featureNames);
        if (res && res.data && res.data.features?.length > 0) {
          res.data.features?.forEach(feature => {
            this.twoLineId.push(feature?.id)
            this.lineObject[feature.name]= feature?.id
          })
        }
      }

      if(this.rootType.includes('CTRIA3') ) {
        let featureNames = [];
        compositeMaterialManageCommand.command.clearCommand();
        for (let i = 0; i < this.allNode?.CTRIA3?.length; i++) {
          let lineId = this.allNode.CTRIA3[i].nodeId;
          let pointId = this.allNode.CTRIA3[i].n1;
          let point1Id = this.allNode.CTRIA3[i].n2;
          let point2Id = this.allNode.CTRIA3[i].n3;

          const point = this.allNode.GRID.find(item => item.nodeId === pointId);
          const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);
          const point2 = this.allNode.GRID.find(item => item.nodeId === point2Id);

          let lId = lineId;
          if(this.fileList1.length) {
            lId = lineId +'new';
          }
          for (let j = 1; j < 4; j++) {
            featureNames.push(j + '三角形' + lId);
          }
          this.createCTRIA3(lId, point, point1, point2);
        }
        await compositeMaterialManageCommand.command.execute();
        let res = await compositeMaterialManageCommand.query.getFeaturesByNames(featureNames);
        if (res && res.data && res.data.features?.length > 0) {
          res.data.features?.forEach(feature => {
            this.threeLineId.push(feature?.id)
            this.lineObject[feature.name]= feature?.id
          })
        }
      }
      compositeMaterialManageCommand.toolQuery.closeLoading();
      console.log("BDF单元CQUAD4：" + this.fourLineId?.length);
      console.log("CTRIA3：" + this.threeLineId?.length);
      console.log("CBAR：" + this.twoLineId?.length);

      this.loading = false;
    },
    createCQUAD4(lineId, point, point1, point2, point3) {
      if(!this.lineNames.includes(1+ '四边形' + lineId)) {
        compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
          pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
          isClosed: 0,
        },1+ '四边形' + lineId)
        this.lineNames.push(1+ '四边形' + lineId)
      }
      if(!this.lineNames.includes(2+ '四边形' + lineId)) {
        let res = compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
          pickPnts: [new Point(point1.x,point1.y,point1.z), new Point(point2.x,point2.y,point2.z)],
          isClosed: 0,
        },2+ '四边形' + lineId)
        this.lineNames.push(2+ '四边形' + lineId)
      }
      if(!this.lineNames.includes(3+ '四边形' + lineId)) {
        let res = compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
          pickPnts: [new Point(point2.x,point2.y,point2.z), new Point(point3.x,point3.y,point3.z)],
          isClosed: 0,
        },3+ '四边形' + lineId)
        this.lineNames.push(3+ '四边形' + lineId)
      }
      if(!this.lineNames.includes(4+ '四边形' + lineId)) {
        let res = compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
          pickPnts: [new Point(point3.x,point3.y,point3.z), new Point(point.x,point.y,point.z)],
          isClosed: 0,
        },4+ '四边形' + lineId)
        this.lineNames.push(4+ '四边形' + lineId)
      }
    },

    createCTRIA3(lineId, point, point1, point2) {
      if(!this.lineNames.includes(1+ '三角形' + lineId)) {
        compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
          pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
          isClosed: 0,
        },1+ '三角形' + lineId)
        this.lineNames.push(1+ '三角形' + lineId)
      }
      if(!this.lineNames.includes(2+ '三角形' + lineId)) {
        compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
          pickPnts: [new Point(point1.x,point1.y,point1.z), new Point(point2.x,point2.y,point2.z)],
          isClosed: 0,
        },2+ '三角形' + lineId)
        this.lineNames.push(2+ '三角形' + lineId)
      }

      if(!this.lineNames.includes(3+ '三角形' + lineId)) {
        compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
          pickPnts: [new Point(point2.x,point2.y,point2.z), new Point(point.x,point.y,point.z)],
          isClosed: 0,
        },3+ '三角形' + lineId)
        this.lineNames.push(3+ '三角形' + lineId)
      }
    },

    async generates4(event) {
      // 阻止冒泡事件
      event.stopPropagation();
      // if (!this.rootType.includes('CQUAD4') || !this.allNode?.CQUAD4) {
      //   let msg = "未获取到单元数据，请检查！"
      //   compositeMaterialManageCommand.eventBusAlertMsg(msg, "error");
      //   return;
      // }
      if (!this.rootType.length) {
        let msg = "请先选择一个单元类型"
        compositeMaterialManageCommand.eventBusAlertMsg(msg, "error");
        return;
      }
      this.loading = true;
      // 没有上传修改单元文件时，按照原始的数据进行生成四边形
      if (this.rootType.includes('CQUAD4')) {
        if(this.fileList1.length) {
          // 将之前绘制的进行隐藏
          await this.setEntityVisible(this.fourLineId);
          await this.setEntityVisible(this.twoLineId);
          await this.setEntityVisible(this.threeLineId);
        }
        let featureNames = [];
        compositeMaterialManageCommand.command.clearCommand();
        for (let i = 0; i < this.allNode?.CQUAD4?.length; i++) {
          let lineId = this.allNode.CQUAD4[i].nodeId;
          let pointId = this.allNode.CQUAD4[i].n1;
          let point1Id = this.allNode.CQUAD4[i].n2;
          let point2Id = this.allNode.CQUAD4[i].n3;
          let point3Id = this.allNode.CQUAD4[i].n4;

          const point = this.allNode.GRID.find(item => item.nodeId === pointId);
          const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);
          const point2 = this.allNode.GRID.find(item => item.nodeId === point2Id);
          const point3 = this.allNode.GRID.find(item => item.nodeId === point3Id);
          let lId = lineId;
          if(this.fileList1.length) {
            lId = lineId +'new';
          }
          for (let j = 1; j < 5; j++) {
            featureNames.push(j + '四边形' + lId);
          }
          await this.createLine4(lId, point, point1, point2,point3);
        }
        // await compositeMaterialManageCommand.command.execute();
        // let res = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames(featureNames);
        // if (res && res.data && res.data.entities?.length > 0) {
        //   console.log("CQUAD4 entitiesLength=" + res.data.entities?.length);
        //   res.data.entities?.forEach(entity => {
        //     this.fourLineId.push(entity?.id);
        //   })
        // }
      }
      if(this.rootType.includes('CBAR') ) {
        let featureNames = [];
        compositeMaterialManageCommand.command.clearCommand();
        for (let i = 0; i <this.allNode?.CBAR?.length ; i++) {
          let lineId= this.allNode.CBAR[i].nodeId;
          let pointId= this.allNode.CBAR[i].n1;
          let point1Id= this.allNode.CBAR[i].n2;

          const point = this.allNode.GRID.find(item => item.nodeId === pointId);
          const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);

          let lId = lineId;
          if(this.fileList1.length) {
            lId = lineId +'new';
          }
          await this.createLine2(lId, point, point1);
          featureNames.push(1 + '直线' + lId);
        }
        // await compositeMaterialManageCommand.command.execute();
        // let res = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames(featureNames);
        // console.log(res);
        // if (res && res.data && res.data.entities?.length > 0) {
        //   console.log("CBAR entitiesLength=" + res.data.entities?.length);
        //   res.data.entities?.forEach(entity => {
        //     this.twoLineId.push(entity?.id);
        //   })
        // }
      }

      if(this.rootType.includes('CTRIA3') ) {
        let featureNames = [];
        compositeMaterialManageCommand.command.clearCommand();
        for (let i = 0; i < this.allNode?.CTRIA3?.length; i++) {
          let lineId = this.allNode.CTRIA3[i].nodeId;
          let pointId = this.allNode.CTRIA3[i].n1;
          let point1Id = this.allNode.CTRIA3[i].n2;
          let point2Id = this.allNode.CTRIA3[i].n3;

          const point = this.allNode.GRID.find(item => item.nodeId === pointId);
          const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);
          const point2 = this.allNode.GRID.find(item => item.nodeId === point2Id);

          let lId = lineId;
          if(this.fileList1.length) {
            lId = lineId +'new';
          }
          for (let j = 1; j < 4; j++) {
            featureNames.push(j + '三角形' + lId);
          }
          await this.createLine3(lId, point, point1, point2);
        }
        // await compositeMaterialManageCommand.command.execute();
        // let res = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames(featureNames);
        // console.log(res);
        // if (res && res.data && res.data.entities?.length > 0) {
        //   console.log("CTRIA3 entitiesLength=" + res.data.entities?.length);
        //   res.data.entities?.forEach(entity => {
        //     this.threeLineId.push(entity?.id);
        //   })
        // }
      }
      console.log("BDF单元CQUAD4：" + this.fourLineId?.length);
      console.log("CTRIA3：" + this.threeLineId?.length);
      console.log("CBAR：" + this.twoLineId?.length);

      this.loading = false;
    },

    async generates5(event) {
      // 阻止冒泡事件
      event.stopPropagation();
      if (this.fibersimData.length=== 0 || this.pcompData.length === 0) {
        compositeMaterialManageCommand.eventBusAlertMsg("未获取到相关数据，请检查！", "error");
        return;
      }
      this.loading = true;
      let res= await compositeMaterialManageCommand.query.getEntities()
      let entitys= []
      res.data.entities.forEach(entity => {
        if(entity.name.includes('导入实体') && entity.name!=='导入实体1' && entity.name!=='导入实体2'&& !entity.name!== '导入实体3' && entity.name!=='导入实体4')
          entitys.push(entity)
      })

      this.entityFaces= {}
      for (let i = 5; i < entitys.length; i++) {
        let res3 = await compositeMaterialManageCommand.query.getElementsByEntityId(entitys[i].id);
        let faceElementId= []
        for (let j = 0; j < res3.data.elements.length; j++) {
          if (res3.data.elements[j].type === 19) {
            faceElementId.push(res3.data.elements[j].id)
          }
        }
        this.entityFaces[entitys[i].name]= faceElementId
      }
      await this.CBARWork(entitys)
      await this.CTRIA3Work(entitys)
      await this.CQUAD4Work(entitys)
      this.loading = false;

      await this.comparisonResult(this.result)
      // 获取newPcomp数据
      // let newPcomp = this.allNode.newPcomp;
      // this.result= [];
      // await this.makeResult(this.allNode.CBAR, newPcomp, 'CBAR');
      // await this.makeResult(this.allNode.CTRIA3, newPcomp, 'CTRIA3');
      // await this.makeResult(this.allNode.CQUAD4, newPcomp, 'CQUAD4');
      // // 四边形newPcomp数据解析出来参数，与导入的材料excel的参数进行对比，输出比对结果
      // // 将生成的比对结果，放到后台，生成excel导出
      // await this.comparisonResult(this.result);
    },
    async CBARWork(entitys) {
      for (let i = 0; i <this.allNode.CBAR.length ; i++) {
        let lineId= this.allNode.CBAR[i].nodeId
        let pcompId= this.allNode.CBAR[i].pcompId
        let pointId= this.allNode.CBAR[i].n1
        let point1Id= this.allNode.CBAR[i].n2
        const point = this.allNode.GRID.find(item => item.nodeId === pointId);
        const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);
        let point4= {x: 0, y: 0, z: 0, nodeId: ''}
        point4.x= (point.x+ point1.x)/2
        point4.y= (point.y+ point1.y )/2
        point4.z= (point.z+ point1.z )/2
        point4.nodeId= lineId +'center'

        let line = [point.x,point.y,point.z*2,point.x,point.y,point.z*-1];
        let line1 = [point1.x,point1.y,point1.z*2,point1.x,point1.y,point1.z*-1];
        let line3 = [point4.x,point4.y,point4.z*2,point4.x,point4.y,point4.z*-1];
        let listLineInfo = [line,line1,line3];

        let ps= []
        let ps1= []
        let ps3= []
        for (let i = 5; i < entitys.length; i++) {
          let faceIds= this.entityFaces[entitys[i].name]
          let result= await this.calculateIntersectFaces(listLineInfo, faceIds)
          if(result[0].length) ps.push(entitys[i])
          if(result[1].length) ps1.push(entitys[i])
          if(result[2].length) ps3.push(entitys[i])
        }
        this.gridLine[point.nodeId]= ps
        this.gridLine[point1.nodeId]= ps
        this.gridLine[point4.nodeId]= ps3
        // console.log(this.gridLine);
        let isNum= 0
        let pcompInfo= this.findPcompInfo(pcompId)
        if(!pcompInfo.length) return
        let e1=[]
        let e2=[]
        let g12=[]
        let poissonRatio= []
        for (let i = 1; i < pcompInfo.length; i++) {
          e1.push(pcompInfo[i].e1)
          e2.push(pcompInfo[i].e2)
          g12.push(pcompInfo[i].g12)
          poissonRatio.push(pcompInfo[i].poissonRatio)
        }

        let gridLine = this.gridLine
        let propertyStr= ''
        let property={}
        let propertySame= true
        let plyData=[]
        for (let i = 0; i < gridLine[point.nodeId].length; i++){
          plyData.push(this.findMaterial(this.plyData[gridLine[point.nodeId][i].name].Material))
        }
        let plyData1=[]
        for (let i = 0; i < gridLine[point1.nodeId].length; i++){
          plyData1.push(this.findMaterial(this.plyData[gridLine[point1.nodeId][i].name].Material))
        }
        let plyData4=[]
        for (let i = 0; i < gridLine[point4.nodeId].length; i++){
          plyData4.push(this.findMaterial(this.plyData[gridLine[point4.nodeId][i].name].Material))
        }
        if(!gridLine[point.nodeId].length) {
          propertyStr= '第1个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= '第1个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr='不一致，第1个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData[i].g12
            }
            break
          }
        }
        if(!gridLine[point1.nodeId].length) {
          propertyStr= propertyStr+ '\n第2个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point1.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData1[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData1[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData1[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData1[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第2个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第2个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData1[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData1[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData1[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData1[i].g12
            }
            break
          }
        }
        if(!gridLine[point4.nodeId].length) {
          propertyStr= propertyStr+ '\n第5个点没有相交的铺层'
        } else {
          for (let i = 0; i < gridLine[point4.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData4[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData4[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData4[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData4[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第3个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第3个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData4[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData4[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData4[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData4[i].g12
            }
            break
          }
        }
        console.log(propertyStr);
        let pocompThickness=[]
        for (let i = 1; i < pcompInfo.length; i++) {
          pocompThickness.push(pcompInfo[i].n1)
        }

        if(pcompInfo.length-1 !== gridLine[point.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point1.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point4.nodeId].length) {
          isNum= isNum+ 1
        }
        let orderResult= '铺层和PCOMP中数量一致的百分比为' + Math.round((1-isNum/3)*100) +'%'

        let thickness=''
        let thicknessSame= true
        if(!this.arraysEqual(plyData, pocompThickness) || !this.arraysEqual(plyData1, pocompThickness) ||
            !this.arraysEqual(plyData4, pocompThickness)) {
          thicknessSame= false
          thickness='第1个点的铺层厚度分别为'+ (plyData.length? plyData.map(item => item.plyThickness).join(',') :'没有经过铺层')+
              '\n第2个点的铺层厚度分别为'+ (plyData1.length? plyData1.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\n第3个点的铺层厚度分别为'+ (plyData4.length? plyData4.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\nPCOMP中铺层厚度分别为' + pocompThickness.join(',')
        } else {
          thickness= '铺层厚度一致，铺层厚度分别为' + pocompThickness.join(',')
        }
        // if((!propertySame || !thicknessSame || isNum) && !this.fileList1.length) {
        //   // let res1 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([1+ '直线' +lineId]);
        //   await this.setEntityColor(this.lineObject[1+ '直线' +lineId])
        // } else if((!propertySame || !thicknessSame || isNum) && this.fileList1.length) {
        //   // let res1 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([1+ '直线' +lineId+'new']);
        //   await this.setEntityColor(1+ '直线' +lineId+'new')
        // }

        this.result.push({
          name: lineId,
          type:'CBAR',
          description: '1、复材结构铺层数量检查；\n2、复材结构铺层厚度检查；\n3、材料属性和材料库对比',
          orderResult: orderResult,
          thicknessResult: thickness,
          propertyResult: propertyStr,
        })
      }
    },

    async CTRIA3Work(entitys) {
      console.log(this.allNode.CTRIA3.length);
      for (let i = 0; i <this.allNode.CTRIA3.length; i++) {
        let lineId= this.allNode.CTRIA3[i].nodeId
        let pcompId= this.allNode.CTRIA3[i].pcompId
        let pointId= this.allNode.CTRIA3[i].n1
        let point1Id= this.allNode.CTRIA3[i].n2
        let point2Id= this.allNode.CTRIA3[i].n3

        const point = this.allNode.GRID.find(item => item.nodeId === pointId);
        const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);
        const point2 = this.allNode.GRID.find(item => item.nodeId === point2Id);

        let point4= {x: 0, y: 0, z: 0, nodeId: ''}
        point4.x= (point.x+ point1.x +point2.x)/3
        point4.y= (point.y+ point1.y +point2.y)/3
        point4.z= (point.z+ point1.z +point2.z)/3
        point4.nodeId= lineId +'center'
        let line = [point.x,point.y,point.z*2,point.x,point.y,point.z*-1];
        let line1 = [point1.x,point1.y,point1.z*2,point1.x,point1.y,point1.z*-1];
        let line2 = [point2.x,point2.y,point2.z*2,point2.x,point2.y,point2.z*-1];
        let line3 = [point4.x,point4.y,point4.z*2,point4.x,point4.y,point4.z*-1];
        let listLineInfo = [line,line1,line2,line3];

        let ps= []
        let ps1= []
        let ps2= []
        let ps3= []
        for (let i = 5; i < entitys.length; i++) {
          let faceIds= this.entityFaces[entitys[i].name]
          let result= await this.calculateIntersectFaces(listLineInfo, faceIds)
          if(result[0].length) ps.push(entitys[i])
          if(result[1].length) ps1.push(entitys[i])
          if(result[2].length) ps2.push(entitys[i])
          if(result[3].length) ps3.push(entitys[i])
        }
        this.gridLine[point.nodeId]= ps
        this.gridLine[point1.nodeId]= ps
        this.gridLine[point2.nodeId]= ps2
        this.gridLine[point4.nodeId]= ps3
        // console.log(this.gridLine);

        let isNum= 0
        let pcompInfo= this.findPcompInfo(pcompId)
        if(!pcompInfo.length) return
        let e1=[]
        let e2=[]
        let g12=[]
        let poissonRatio= []
        for (let i = 1; i < pcompInfo.length; i++) {
          e1.push(pcompInfo[i].e1)
          e2.push(pcompInfo[i].e2)
          g12.push(pcompInfo[i].g12)
          poissonRatio.push(pcompInfo[i].poissonRatio)
        }

        let gridLine = this.gridLine
        let propertyStr= ''
        let property={}
        let propertySame= true

        let plyData=[]
        for (let i = 0; i < gridLine[point.nodeId].length; i++){
          plyData.push(this.findMaterial(this.plyData[gridLine[point.nodeId][i].name].Material))
        }
        let plyData1=[]
        for (let i = 0; i < gridLine[point1.nodeId].length; i++){
          plyData1.push(this.findMaterial(this.plyData[gridLine[point1.nodeId][i].name].Material))
        }
        let plyData2=[]
        for (let i = 0; i < gridLine[point2.nodeId].length; i++){
          plyData2.push(this.findMaterial(this.plyData[gridLine[point2.nodeId][i].name].Material))
        }
        let plyData4=[]
        for (let i = 0; i < gridLine[point4.nodeId].length; i++){
          plyData4.push(this.findMaterial(this.plyData[gridLine[point4.nodeId][i].name].Material))
        }

        if(!gridLine[point.nodeId].length) {
          propertyStr= '第1个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= '第1个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr='不一致，第1个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData[i].g12
            }
            break
          }
        }
        if(!gridLine[point1.nodeId].length) {
          propertyStr= propertyStr+ '\n第2个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point1.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData1[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData1[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData1[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData1[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第2个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第2个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData1[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData1[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData1[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData1[i].g12
            }
            break
          }
        }

        if(!gridLine[point2.nodeId].length) {
          propertyStr= propertyStr+ '\n第3个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point2.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData2[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData2[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData2[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData2[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第3个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第3个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData2[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData2[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData2[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData2[i].g12
            }
            break
          }
        }

        if(!gridLine[point4.nodeId].length) {
          propertyStr= propertyStr+ '\n第4个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point4.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData4[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData4[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData4[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData4[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第4个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第4个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData4[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData4[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData4[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData4[i].g12
            }
            break
          }
        }
        // console.log(propertyStr);
        let pocompThickness=[]
        for (let i = 1; i < pcompInfo.length; i++) {
          pocompThickness.push(pcompInfo[i].n1)
        }

        if(pcompInfo.length-1 !== gridLine[point.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point1.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point2.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point4.nodeId].length) {
          isNum= isNum+ 1
        }
        let orderResult= '铺层和PCOMP中数量一致的百分比为' + Math.round((1-isNum/4)*100) +'%'
        let thickness=''
        let thicknessSame= true
        if(!this.arraysEqual(plyData, pocompThickness) || !this.arraysEqual(plyData1, pocompThickness) ||
            !this.arraysEqual(plyData2, pocompThickness)  || !this.arraysEqual(plyData4, pocompThickness)) {
          thicknessSame= false
          thickness='第1个点的铺层厚度分别为'+ (plyData.length? plyData.map(item => item.plyThickness).join(',') :'没有经过铺层')+
              '\n第2个点的铺层厚度分别为'+ (plyData1.length? plyData1.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\n第3个点的铺层厚度分别为'+ (plyData2.length? plyData2.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\n第4个点的铺层厚度分别为'+ (plyData4.length? plyData4.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\nPCOMP中铺层厚度分别为' + pocompThickness.join(',')
        } else {
          thickness= '铺层厚度一致，铺层厚度分别为' + pocompThickness.join(',')
        }

        console.log(thickness);
        this.result.push({
          name: lineId,
          type:'CTRIA3',
          description: '1、复材结构铺层数量检查；\n2、复材结构铺层厚度检查；\n3、材料属性和材料库对比',
          orderResult: orderResult,
          thicknessResult: thickness,
          propertyResult: propertyStr,
        })
        // // 根据比对接口设置四边形颜色
        // if((!propertySame || !thicknessSame || isNum) && !this.fileList1.length) {
        //   // let res1 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([1+ '三角形' +lineId]);
        //   // let res2 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([2+ '三角形' +lineId]);
        //   // let res3 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([3+ '三角形' +lineId]);
        //   await this.setEntityColor(this.lineObject[1+ '三角形' +lineId])
        //   await this.setEntityColor(this.lineObject[2+ '三角形' +lineId])
        //   await this.setEntityColor(this.lineObject[3+ '三角形' +lineId])
        // } else if((!propertySame || !thicknessSame || isNum) && this.fileList1.length) {
        //   // let res1 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([1+ '三角形' +lineId+'new']);
        //   // let res2 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([2+ '三角形' +lineId+'new']);
        //   // let res3 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([3+ '三角形' +lineId+'new']);
        //   await this.setEntityColor(this.lineObject[1+ '三角形' +lineId+'new'])
        //   await this.setEntityColor(this.lineObject[2+ '三角形' +lineId+'new'])
        //   await this.setEntityColor(this.lineObject[3+ '三角形' +lineId+'new'])
        // }
      }
    },

    async CQUAD4Work(entitys) {
      console.log("entities.length=" + entitys.length);
      for (let i = 0; i <this.allNode.CQUAD4.length; i++) {
        let lineId= this.allNode.CQUAD4[i].nodeId
        let pcompId= this.allNode.CQUAD4[i].pcompId
        let pointId= this.allNode.CQUAD4[i].n1
        let point1Id= this.allNode.CQUAD4[i].n2
        let point2Id= this.allNode.CQUAD4[i].n3
        let point3Id= this.allNode.CQUAD4[i].n4

        const point = this.allNode.GRID.find(item => item.nodeId === pointId);
        const point1 = this.allNode.GRID.find(item => item.nodeId === point1Id);
        const point2 = this.allNode.GRID.find(item => item.nodeId === point2Id);
        const point3 = this.allNode.GRID.find(item => item.nodeId === point3Id);

        let point4= {x: 0, y: 0, z: 0, nodeId: ''}
        point4.x= (point.x+ point1.x +point2.x+ point3.x)/4
        point4.y= (point.y+ point1.y +point2.y+ point3.y)/4
        point4.z= (point.z+ point1.z +point2.z+ point3.z)/4
        point4.nodeId= lineId +'center'
        let line = [point.x,point.y,point.z*2,point.x,point.y,point.z*-1];
        let line1 = [point1.x,point1.y,point1.z*2,point1.x,point1.y,point1.z*-1];
        let line2 = [point2.x,point2.y,point2.z*2,point2.x,point2.y,point2.z*-1];
        let line3 = [point3.x,point3.y,point3.z*2,point3.x,point3.y,point3.z*-1];
        let line4 = [point4.x,point4.y,point4.z*2,point4.x,point4.y,point4.z*-1];
        let listLineInfo = [line,line1,line2,line3,line4];

        let ps= []
        let ps1= []
        let ps2= []
        let ps3= []
        let ps4= []
        for (let i = 5; i < entitys.length; i++) {
          let faceIds= this.entityFaces[entitys[i].name]
          let result= await this.calculateIntersectFaces(listLineInfo, faceIds)
          if(result[0].length) ps.push(entitys[i])
          if(result[1].length) ps1.push(entitys[i])
          if(result[2].length) ps2.push(entitys[i])
          if(result[3].length) ps3.push(entitys[i])
          if(result[4].length) ps4.push(entitys[i])
        }
        this.gridLine[point.nodeId]= ps
        this.gridLine[point1.nodeId]= ps
        this.gridLine[point2.nodeId]= ps2
        this.gridLine[point3.nodeId]= ps3
        this.gridLine[point4.nodeId]= ps4
        // console.log(this.gridLine);

        let isNum= 0
        let pcompInfo= this.findPcompInfo(pcompId)
        if(!pcompInfo.length) return
        let e1=[]
        let e2=[]
        let g12=[]
        let poissonRatio= []
        for (let i = 1; i < pcompInfo.length; i++) {
          e1.push(pcompInfo[i].e1)
          e2.push(pcompInfo[i].e2)
          g12.push(pcompInfo[i].g12)
          poissonRatio.push(pcompInfo[i].poissonRatio)
        }

        let gridLine = this.gridLine
        let propertyStr= ''
        let property={}
        let propertySame= true

        let plyData=[]
        for (let i = 0; i < gridLine[point.nodeId].length; i++){
          plyData.push(this.findMaterial(this.plyData[gridLine[point.nodeId][i].name].Material))
        }
        let plyData1=[]
        for (let i = 0; i < gridLine[point1.nodeId].length; i++){
          plyData1.push(this.findMaterial(this.plyData[gridLine[point1.nodeId][i].name].Material))
        }
        let plyData2=[]
        for (let i = 0; i < gridLine[point2.nodeId].length; i++){
          plyData2.push(this.findMaterial(this.plyData[gridLine[point2.nodeId][i].name].Material))
        }
        let plyData3=[]
        for (let i = 0; i < gridLine[point3.nodeId].length; i++){
          plyData3.push(this.findMaterial(this.plyData[gridLine[point3.nodeId][i].name].Material))
        }
        let plyData4=[]
        for (let i = 0; i < gridLine[point4.nodeId].length; i++){
          plyData4.push(this.findMaterial(this.plyData[gridLine[point4.nodeId][i].name].Material))
        }

        if(!gridLine[point.nodeId].length) {
          propertyStr= '第1个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= '第1个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr='不一致，第1个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData[i].g12
            }
            break
          }
        }
        if(!gridLine[point1.nodeId].length) {
          propertyStr= propertyStr+ '\n第2个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point1.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData1[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData1[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData1[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData1[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第2个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第2个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData1[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData1[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData1[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData1[i].g12
            }
            break
          }
        }

        if(!gridLine[point2.nodeId].length) {
          propertyStr= propertyStr+ '\n第3个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point2.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData2[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData2[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData2[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData2[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第3个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第3个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData2[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData2[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData2[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData2[i].g12
            }
            break
          }
        }

        if(!gridLine[point3.nodeId].length) {
          propertyStr= propertyStr+ '\n第4个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point3.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData3[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData3[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData3[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData3[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第4个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第4个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData3[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData3[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData3[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData3[i].g12
            }
            break
          }
        }

        if(!gridLine[point4.nodeId].length) {
          propertyStr= propertyStr+ '\n第5个点没有相交的铺层'
          propertySame= false
        } else {
          for (let i = 0; i < gridLine[point4.nodeId].length; i++){
            property.e1= this.compareDecimals(e1[i],plyData4[i].e1)
            property.e2= this.compareDecimals(e2[i],plyData4[i].e2)
            property.poissonRatio= this.compareDecimals(poissonRatio[i],plyData4[i].poissonRatio)
            property.g12= this.compareDecimals(g12[i],plyData4[i].g12)
            if(Object.values(property).every(value => value === true)) {
              propertyStr= propertyStr + '\n第5个点BDF中的材料属性和材料库中的属性值一致'
            } else {
              propertySame= false
              propertyStr=propertyStr +'\n不一致，第5个点BDF中的材料属性和材料库中的E1分别为'+e1[i]+'和' + plyData4[i].e1+
                  ',E2分别为' + e2[i]+'和' + plyData4[i].e2+
                  ',泊松比分别为' +poissonRatio[i]+'和' + plyData4[i].poissonRatio+
                  ',G12分别为' + g12[i]+'和' + plyData4[i].g12
            }
            break
          }
        }
        console.log(propertyStr);
        let pocompThickness=[]
        for (let i = 1; i < pcompInfo.length; i++) {
          pocompThickness.push(pcompInfo[i].n1)
        }

        if(pcompInfo.length-1 !== gridLine[point.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point1.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point2.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point3.nodeId].length) {
          isNum= isNum+ 1
        }
        if(pcompInfo.length-1 !== gridLine[point4.nodeId].length) {
          isNum= isNum+ 1
        }
        let orderResult= '铺层和PCOMP中数量一致的百分比为' + Math.round((1-isNum/5)*100) +'%'
        let thickness= ''
        let thicknessSame= true
        if(!this.arraysEqual(plyData, pocompThickness) || !this.arraysEqual(plyData1, pocompThickness) ||
            !this.arraysEqual(plyData2, pocompThickness) || !this.arraysEqual(plyData3, pocompThickness) ||
            !this.arraysEqual(plyData4, pocompThickness)) {
          thicknessSame= false
          thickness='第1个点的铺层厚度分别为'+ (plyData.length? plyData.map(item => item.plyThickness).join(',') :'没有经过铺层')+
              '\n第2个点的铺层厚度分别为'+ (plyData1.length? plyData1.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\n第3个点的铺层厚度分别为'+ (plyData2.length? plyData2.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\n第4个点的铺层厚度分别为'+ (plyData3.length? plyData3.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\n第5个点的铺层厚度分别为'+ (plyData4.length? plyData4.map(item => item.plyThickness).join(',') :'没有经过铺层') +
              '\nPCOMP中铺层厚度分别为' + pocompThickness.join(',')
        } else {
          thickness= '铺层厚度一致，铺层厚度分别为' + pocompThickness.join(',')
        }

        console.log('CQUAD4'+ i);
        // 根据比对接口设置四边形颜色
        // if((!propertySame || !thicknessSame || isNum) && !this.fileList1.length) {
        //   // let res1 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([1+ '四边形' +lineId]);
        //   // let res2 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([2+ '四边形' +lineId]);
        //   // let res3 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([3+ '四边形' +lineId]);
        //   // let res4 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([4+ '四边形' +lineId]);
        //   await this.setEntityColor(this.lineObject[1+ '四边形' +lineId])
        //   await this.setEntityColor(this.lineObject[2+ '四边形' +lineId])
        //   await this.setEntityColor(this.lineObject[3+ '四边形' +lineId])
        //   await this.setEntityColor(this.lineObject[4+ '四边形' +lineId])
        // } else if((!propertySame || !thicknessSame || isNum) && this.fileList1.length) {
        //   // let res1 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([1+ '四边形' +lineId+'new']);
        //   // let res2 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([2+ '四边形' +lineId+'new']);
        //   // let res3 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([3+ '四边形' +lineId+'new']);
        //   // let res4 = await this.crownCADPlugin.query.getEntitiesByFeatureNames([4+ '四边形' +lineId+'new']);
        //   await this.setEntityColor(this.lineObject[1+ '四边形' +lineId+'new'])
        //   await this.setEntityColor(this.lineObject[2+ '四边形' +lineId+'new'])
        //   await this.setEntityColor(this.lineObject[3+ '四边形' +lineId+'new'])
        //   await this.setEntityColor(this.lineObject[4+ '四边形' +lineId+'new'])
        // }
        this.result.push({
          name: lineId,
          type:'CQUAD4',
          description: '1、复材结构铺层数量检查；\n2、复材结构铺层厚度检查；\n3、材料属性和材料库对比',
          orderResult: orderResult,
          thicknessResult: thickness,
          propertyResult: propertyStr,
        })

      }
    },

    arraysEqual(plyData, pocompThickness) {
      let arr1 = plyData.map(item => item.plyThickness);
      return arr1.join(',')=== pocompThickness.join(',')
    },

    async calculateIntersectFaces(listLineInfo, faceIds) {
      let facesParam = [];
      let mapFaceInfo = [];
      faceIds.forEach(faceId => {
        facesParam.push({
          id:faceId,
          //装配ID，零件下填null,装配下填instanceid
          instanceId: null,  //字符串
        })
      })
      let facesInfo = await compositeMaterialManageCommand.toolQuery.getFacesPoints(facesParam);
      if(faceIds?.length != facesInfo?.data?.length){
        return;
      }

      for(let n = 0;n < faceIds.length;n++) {
        mapFaceInfo.push({
          'id': faceIds[n],
          'data': facesInfo.data[n]
        });
      }
      //获取到的有相交的ID，每条线段可能对应多个，列表的形式，获取的结果
      let intersectFaceInfo = await this.calculateIntersectFacesRequest(listLineInfo,mapFaceInfo);
      return intersectFaceInfo;
    },

    findPcompInfo(pcompId) {
      for (let i = 0; i <this.pcompData.length ; i++) {
        if(this.pcompData[i][0].n0=== pcompId+ '') {
          return this.pcompData[i]
        }
      }
      return []
    },

    findMaterial(ccode) {
      for (let i = 0; i <this.fibersimData.length ; i++) {
        if(this.fibersimData[i].materialCode=== ccode) {
          return this.fibersimData[i]
        }
      }
    },
    async makeResult(gridList, newPcomp, name) {
      if(!gridList) {
        return;
      }
      for(let i = 0; i <gridList.length ; i++) {
        let thicknessResult1= [];
        let property={};
        let propertyStr= '';
        for (let j = 0; j <this.newPly.length ; j++) {
          let temp= this.newPly[j].plyThickness-parseFloat(newPcomp[j].n1);
          thicknessResult1.push(temp=== 0? 0: temp.toFixed(2));
        }
        for (let j = 0; j <this.newPly.length ; j++) {
          property.tensileModulus= this.compareDecimals(this.newPly[j].tensileModulus,parseFloat(newPcomp[j].tensileModulus)/1000000);
          property.compressiveModulus= this.compareDecimals(this.newPly[j].compressiveModulus,parseFloat(newPcomp[j].compressiveModulus)/1000000);
          property.poissonRatio= this.compareDecimals(this.newPly[j].poissonRatio,parseFloat(newPcomp[j].poissonRatio));
          property.shearModulus= this.compareDecimals(this.newPly[j].shearModulus,parseFloat(newPcomp[j].shearModulus)/1000000);
          property.primaryThermalExpansion= this.compareDecimals(this.newPly[j].primaryThermalExpansion,parseFloat(newPcomp[j].primaryThermalExpansion));
          property.secondaryThermalExpansion= this.compareDecimals(this.newPly[j].secondaryThermalExpansion,parseFloat(newPcomp[j].secondaryThermalExpansion));
          if(Object.values(property).every(value => value === true)) {
            propertyStr= '一致';
          } else {
            propertyStr= '不一致,BDF中的材料属性和材料库中的拉伸弹性模量（GPa）、压缩弹性模量（GPa）、泊松比、剪切模量（GPa）、' +
              '主向热膨胀系数、次向热膨胀系数分别是'+ parseFloat(newPcomp[j].tensileModulus)/1000000 +',' + parseFloat(newPcomp[j].compressiveModulus)/1000000 +',' + parseFloat(newPcomp[j].poissonRatio) +',' + parseFloat(newPcomp[j].shearModulus)/1000000 +','
              + parseFloat(newPcomp[j].primaryThermalExpansion).toString() +',' + parseFloat(newPcomp[j].secondaryThermalExpansion).toString() +'和'+ this.newPly[j].tensileModulus+ ','+ this.newPly[j].compressiveModulus+ ','+
              this.newPly[j].poissonRatio+ ','+ this.newPly[j].shearModulus+ ','+ this.newPly[j].primaryThermalExpansion.toString()+ ','+ this.newPly[j].secondaryThermalExpansion.toString();
            break;
          }
        }
        this.result.push({
          name: name + ' '+ gridList[i].nodeId,
          description: '1、复材结构铺层顺序检查；\n2、复材结构铺层厚度检查；\n3、材料属性和材料库对比',
          orderResult: '铺层和PCOMP中顺序一致的百分比为100%',
          thicknessResult: '铺层厚度和PCOMP中差别(mm)依次为:' + thicknessResult1.join(', '),
          propertyResult: propertyStr,
        });

        // 根据比对接口设置四边形颜色
        // if(propertyStr!== '一致' && !this.fileList1.length) {
        //   let res1 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId]);
        //   let res2 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId]);
        //   let res3 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId]);
        //   let res4 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId]);
        //   await this.setEntityColor(res1.data.entities[0]?.id);
        //   await this.setEntityColor(res2.data.entities[0]?.id);
        //   await this.setEntityColor(res3.data.entities[0]?.id);
        //   await this.setEntityColor(res4.data.entities[0]?.id);
        // } else if(propertyStr!== '一致' && this.fileList1.length) {
        //   let res1 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId+'new']);
        //   let res2 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId+'new']);
        //   let res3 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId+'new']);
        //   let res4 = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '四边形' +gridList[i].nodeId+'new']);
        //   await this.setEntityColor(res1.data.entities[0]?.id);
        //   await this.setEntityColor(res2.data.entities[0]?.id);
        //   await this.setEntityColor(res3.data.entities[0]?.id);
        //   await this.setEntityColor(res4.data.entities[0]?.id);
        // }
      }
    },

    pcomOrder(id) {
      return true;
    },

    compareDecimals(a, b) {
      return parseFloat(a).toFixed(10) === parseFloat(b).toFixed(10);
    },

    async setEntityVisible(entityIds) {
      compositeMaterialManageCommand.command.clearCommand();
      compositeMaterialManageCommand.command.common.setEntityVisible({
        entityIds, visibleType: 0,
      });
      await compositeMaterialManageCommand.command.execute();
    },

    async setEntityColor(entityId) {
      compositeMaterialManageCommand.command.clearCommand();
      compositeMaterialManageCommand.command.common.setEntityColor({
        entityId: entityId,
        color: '#00FF00',
        opacity: 1,
      });
      await compositeMaterialManageCommand.command.execute();
    },

    async createPoint(pointId, datumId, x, y) {
      compositeMaterialManageCommand.command.clearCommand();
      //绘制上翼面草图，命名为sketch1
      compositeMaterialManageCommand.command.sketch.createSketch({
        sketchName: pointId,
        datumId: datumId
      });
      //创建放样曲线
      compositeMaterialManageCommand.command.sketch.createPoint({x, y});
      //退出草图
      compositeMaterialManageCommand.command.sketch.exitSketch();
      //实现草图操作，参数true会覆盖之前的草图，不传则不会
      await compositeMaterialManageCommand.command.execute();
    },

    async create3DPoint(gridNode) {
      compositeMaterialManageCommand.command.clearCommand();
      //绘制上翼面草图，命名为sketch1
      compositeMaterialManageCommand.command.sketch.create3DSketch({
        sketchName: gridNode.nodeId,
      });
      //创建放样曲线
      let X = gridNode.x;
      let Y = gridNode.y;
      let Z = gridNode.z;
      compositeMaterialManageCommand.command.sketch.create3DPoint({X, Y, Z});
      //退出草图
      compositeMaterialManageCommand.command.sketch.exitSketch();
      //实现草图操作，参数true会覆盖之前的草图，不传则不会
      await compositeMaterialManageCommand.command.execute();
    },

    async createLine4(lineId, point, point1, point2, point3) {
      // compositeMaterialManageCommand.command.clearCommand();
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point.x, point.y, point.z), new Point(point1.x, point1.y, point1.z)],
      //   isClosed: 0,
      // }, 1 + '四边形' + lineId);
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point1.x, point1.y, point1.z), new Point(point2.x, point2.y, point2.z)],
      //   isClosed: 0,
      // }, 2 + '四边形' + lineId);
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point2.x, point2.y, point2.z), new Point(point3.x, point3.y, point3.z)],
      //   isClosed: 0,
      // }, 3 + '四边形' + lineId);
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point3.x, point3.y, point3.z), new Point(point.x, point.y, point.z)],
      //   isClosed: 0,
      // }, 4 + '四边形' + lineId);
      if(!this.lineNames.includes(1+ '四边形' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
          isClosed: 0,
        },1+ '四边形' + lineId)
        this.lineNames.push(1+ '四边形' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[1+ '四边形' + lineId]= res.data.modelData.currentFeature[0]?.id
      }
      if(!this.lineNames.includes(2+ '四边形' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point1.x,point1.y,point1.z), new Point(point2.x,point2.y,point2.z)],
          isClosed: 0,
        },2+ '四边形' + lineId)
        this.lineNames.push(2+ '四边形' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[2+ '四边形' + lineId]= res.data.modelData.currentFeature[0]?.id
      }
      if(!this.lineNames.includes(3+ '四边形' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point2.x,point2.y,point2.z), new Point(point3.x,point3.y,point3.z)],
          isClosed: 0,
        },3+ '四边形' + lineId)
        this.lineNames.push(3+ '四边形' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[3+ '四边形' + lineId]= res.data.modelData.currentFeature[0]?.id
      }
      if(!this.lineNames.includes(4+ '四边形' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point3.x,point3.y,point3.z), new Point(point.x,point.y,point.z)],
          isClosed: 0,
        },4+ '四边形' + lineId)
        this.lineNames.push(4+ '四边形' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[4+ '四边形' + lineId]= res.data.modelData.currentFeature[0]?.id
      }
      // await compositeMaterialManageCommand.command.execute();
      // for (let i = 1; i < 5; i++) {
      //   let res = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([i + '四边形' + lineId]);
      //   this.fourLineId.push(res.data.entities[0]?.id);
      // }
    },
    async createLine2(lineId, point, point1) {
      // compositeMaterialManageCommand.command.clearCommand();
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
      //   isClosed: 0,
      // },1+ '直线' + lineId);

      if(!this.lineNames.includes(1+ '直线' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
          isClosed: 0,
        },1+ '直线' + lineId)
        this.lineNames.push(1+ '直线' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[1+ '直线' + lineId]= res.data.modelData.currentFeature[0]?.id
      }

      // await compositeMaterialManageCommand.command.execute();
      // let res = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([1+ '直线' + lineId]);
      // this.twoLineId.push(res.data.entities[0]?.id);
    },

    async createLine3(lineId, point, point1, point2) {
      // compositeMaterialManageCommand.command.clearCommand();
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
      //   isClosed: 0,
      // },1+ '三角形' + lineId);
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point1.x,point1.y,point1.z), new Point(point2.x,point2.y,point2.z)],
      //   isClosed: 0,
      // },2+ '三角形' + lineId);
      // compositeMaterialManageCommand.command.curve.createCurveByInterpolationPoints({
      //   pickPnts: [new Point(point2.x,point2.y,point2.z), new Point(point.x,point.y,point.z)],
      //   isClosed: 0,
      // },3+ '三角形' + lineId);

      if(!this.lineNames.includes(1+ '三角形' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point.x,point.y,point.z), new Point(point1.x,point1.y,point1.z)],
          isClosed: 0,
        },1+ '三角形' + lineId)
        this.lineNames.push(1+ '三角形' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[1+ '三角形' + lineId]= res.data.modelData.currentFeature[0]?.id
      }
      if(!this.lineNames.includes(2+ '三角形' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point1.x,point1.y,point1.z), new Point(point2.x,point2.y,point2.z)],
          isClosed: 0,
        },2+ '三角形' + lineId)
        this.lineNames.push(2+ '三角形' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[2+ '三角形' + lineId]= res.data.modelData.currentFeature[0]?.id
      }

      if(!this.lineNames.includes(3+ '三角形' + lineId)) {
        let res =await compositeMaterialManageCommand.command.curve.createCurveByInterpolationPointsIncrement({
          pickPnts: [new Point(point2.x,point2.y,point2.z), new Point(point.x,point.y,point.z)],
          isClosed: 0,
        },3+ '三角形' + lineId)
        this.lineNames.push(3+ '三角形' + lineId)
        this.fourLineId.push(res.data.modelData.currentFeature[0]?.id)
        this.lineObject[3+ '三角形' + lineId]= res.data.modelData.currentFeature[0]?.id
      }

      // await compositeMaterialManageCommand.command.execute();
      // for (let i = 1; i <4 ; i++) {
      //   let res = await compositeMaterialManageCommand.query.getEntitiesByFeatureNames([i+ '三角形' + lineId]);
      //   this.threeLineId.push(res.data.entities[0]?.id);
      // }
    },
    async getBdfExcelData(excelData) {
      let excelDataTemp = {CBAR: [], CTRIA3: [], CQUAD4: [], GRID: []}
      for (let i = 0; i < excelData.length; i++) {
        if (excelData[i].nodeName === 'CTRIA3') {
          excelDataTemp.CTRIA3.push(excelData[i]);
        } else if (excelData[i].nodeName === 'CQUAD4') {
          excelDataTemp.CQUAD4.push(excelData[i]);
        } else if (excelData[i].nodeName === 'CBAR') {
          excelDataTemp.CBAR.push(excelData[i]);
        } else if (excelData[i].nodeName === 'GRID') {
          excelDataTemp.GRID.push(excelData[i]);
        }
      }

      excelDataTemp.GRID.map(item => {
        item.x = parseFloat(item.n1);
        item.y = parseFloat(item.n2);
        item.z = parseFloat(item.n3);
      })
      if (this.rootType.includes('CBAR')) {
        this.allNode.CBAR = excelDataTemp.CBAR;
      }
      if(this.rootType.includes('CTRIA3')) {
        this.allNode.CTRIA3= excelDataTemp.CTRIA3;
      }
      if(this.rootType.includes('CQUAD4')) {
        this.allNode.CQUAD4= excelDataTemp.CQUAD4;
      }
      console.log(this.allNode);
    },

    async uploadFile(file) {
      try {
        // const formData = new FormData();
        // formData.append('file', file); // file 是从 <input type="file"> 获取的文件对象
        //
        // const response = await axios.post(window.requestUrl + 'uploadBdf', formData, {
        //   headers: {
        //     'Content-Type': 'multipart/form-data',
        //   },
        // });
        let response = await compositeMaterialManageCommand.uploadBdfRequset(file);
        console.log(response, 432534);
        // 该接口返回所有节点数据，然后存储到allNode中
        this.allNode = response.data;
        // allNode中pcomp重新组装成newPcomp
        for (let i = 0; i <this.allNode.mat.length ; i++) {
          for (let j = 1; j <this.allNode.pcomp.length ; j++) {
            if(this.allNode.mat[i].elementId==this.allNode.pcomp[j].n0) {
              // this.allNode.newPcomp.push({...this.allNode.pcomp[j],...this.allNode.mat[i]})
              this.allNode.pcomp[j].e1= this.allNode.mat[i].e1
              this.allNode.pcomp[j].e2= this.allNode.mat[i].e2
              this.allNode.pcomp[j].g12= this.allNode.mat[i].g12
              this.allNode.pcomp[j].poissonRatio= this.allNode.mat[i].poissonRatio
            }
          }
        }
        console.log(this.allNode);
        this.pcompData= this.splitAndMaybeReverse(this.allNode.pcomp, 'pcomp', 'PCOMP', 'n2', 'SYM')                               // 该字段等于什么值时追加倒序)

        console.log(this.pcompData);
        console.log('文件上传成功:', this.allNode);
        // await this.generates()
      } catch (error) {
        console.error('文件上传失败:', error.response ? error.response.data : error.message);
      }
    },
    splitAndMaybeReverse(array, startKey, startValue, reverseKey, reverseValue) {
      const result = [];

      // 找出所有作为起点的索引（满足 item[startKey] === startValue）
      const indices = array
          .map((item, index) => (item[startKey] === startValue ? index : -1))
          .filter(index => index !== -1);

      for (let i = 0; i < indices.length; i++) {
        const start = indices[i];
        const end = i < indices.length - 1 ? indices[i + 1] : array.length;

        // 提取当前段：从当前 start 到下一个 start 之前
        const segment = array.slice(start, end);

        // 检查当前起点是否满足“需要倒序追加”的条件
        const needReverse = array[start][reverseKey] === reverseValue;

        if (needReverse) {
          // 追加：除第一个元素外，其余倒序
          const reversed = segment.slice(1).reverse(); // 倒序非头元素
          result.push([...segment, ...reversed]);      // 拼接
        } else {
          // 不追加，直接返回原段
          result.push(segment);
        }
      }

      return result;
    },
    async uploadFile1(file) {
      try {
        // const formData = new FormData();
        // formData.append('file', file); // file 是从 <input type="file"> 获取的文件对象
        //
        // const response = await axios.post(window.requestUrl + 'uploadBdfExcel', formData, {
        //   headers: {
        //     'Content-Type': 'multipart/form-data',
        //   },
        // });
        let response = await compositeMaterialManageCommand.uploadBdfExcelRequest(file);
        console.log('文件上传成功:', response.data);
        await this.getBdfExcelData(response.data);
      } catch (error) {
        console.error('文件上传失败:', error.response ? error.response.data : error.message);
      }
    },

    async uploadFile2(file) {
      try {
        // const formData = new FormData();
        // formData.append('file', file); // file 是从 <input type="file"> 获取的文件对象
        //
        // const response = await axios.post(window.requestUrl + 'uploadXml', formData, {
        //   headers: {
        //     'Content-Type': 'multipart/form-data',
        //   },
        // });
        let response = await compositeMaterialManageCommand.uploadXMLRequest(file);
        console.log('文件上传成功:', response.data);
        this.xmlData= response.data
        let plys= response.data.Root.children[0].PartRoot.children
        let plyDetail= []

        for (let i = 0; i <plys.length ; i++) {
          this.plyData[plys[i].Ply.CCcode]= plys[i].Ply
        }
        console.log(this.plyData);
        this.plyDetail= plyDetail
        this.newPly= []
        for (let i = 0; i < this.fibersimData.length; i++) {
          for (let j = 0; j < plyDetail.length; j++) {
            if(plyDetail[j].category===this.fibersimData[i].materialCode) {
              this.newPly.push({...plyDetail[j],...this.fibersimData[i]})
            }
          }
        }
      } catch (error) {
        console.error('文件上传失败:', error.response ? error.response.data : error.message);
      }
    },

    async uploadFile3(file) {
      try {
        // const formData = new FormData();
        // formData.append('file', file); // file 是从 <input type="file"> 获取的文件对象
        //
        // const response = await axios.post(window.requestUrl + 'uploadFibersimExcel', formData, {
        //   headers: {
        //     'Content-Type': 'multipart/form-data',
        //   },
        // });
        let response = await compositeMaterialManageCommand.uploadFibersimExcelRequest(file);
        console.log('文件上传成功:', response.data);
        this.fibersimData = response.data;
      } catch (error) {
        console.error('文件上传失败:', error.response ? error.response.data : error.message);
      }
    },

    async bdfToExcel(excelData) {
      try {
        // const response = await axios.post(window.requestUrl + 'exportBdfToExcel', excelData, {
        //   responseType: 'blob', // 告诉 axios 返回的数据是二进制流
        // });
        let response = await compositeMaterialManageCommand.bdfToExcelRequest(excelData);
        console.log(response.data);
        const disposition = response.headers['content-disposition'];
        const matches = /"([^"]+)"/.exec(disposition);
        const filename = matches ? matches[1] : 'output2.xlsx';

        // 创建一个 URL 对象
        const url = window.URL.createObjectURL(new Blob([response.data]));

        // 创建一个 <a> 元素并触发点击事件以下载文件
        const a = document.createElement('a');
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();

        // 释放 URL 对象
        window.URL.revokeObjectURL(url);
      } catch (error) {
        console.error('调用失败:', error.response ? error.response.data : error.message);
      }
    },
    async calculateIntersectFacesRequest(linesParam,facesParam){
      // let url = "bdfAnalysis/getIntersectFaces";
      // const formData = new FormData();
      // formData.append('linesInfo', linesParam); //line的信息，
      // formData.append('facesInfo', facesParam); //face的键值对，键对应的id，值对应的获取的点集
      // let data = {
      //   'linesInfo': linesParam,
      //   'facesInfo': facesParam
      // }
      // const response = await axios.post(window.requestUrl +  url, data, {
      //   headers: {
      //     'Cache-Control': 'no-cache',
      //   },
      // });
      let response = await compositeMaterialManageCommand.calculateIntersectFacesRequest(linesParam,facesParam);
      // console.log(response.data);
      return response.data
    },

    async comparisonResult(excelData) {
      try {
        // const response = await axios.post(window.requestUrl + 'comparisonResult', excelData, {
        //   responseType: 'blob', // 告诉 axios 返回的数据是二进制流
        // });
        let response = await compositeMaterialManageCommand.comparisonResultRequest(excelData);
        console.log(response.data);
        const disposition = response.headers['content-disposition'];
        const matches = /"([^"]+)"/.exec(disposition);
        const filename = matches ? matches[1] : 'output1.xlsx';

        // 创建一个 URL 对象
        const url = window.URL.createObjectURL(new Blob([response.data]));

        // 创建一个 <a> 元素并触发点击事件以下载文件
        const a = document.createElement('a');
        a.href = url;
        a.download = filename;
        document.body.appendChild(a);
        a.click();

        // 释放 URL 对象
        window.URL.revokeObjectURL(url);
      } catch (error) {
        console.error('调用失败:', error.response ? error.response.data : error.message);
      }
    },

    changeHeight() {
      let height = 0;
      let height1 = 0;
      let height2 = 0;
      let height3 = 0;
      if(this.fileList.length > 0) {
        height1 += 35;
        height += 35;
      }
      if(this.fileList1.length > 0) {
        height2 += 35;
        height += 35;
      }
      if(this.fileList2.length > 0) {
        height3 += 35;
        height += 35;
      }
      if(this.fileList3.length > 0) {
        height3 += 35;
        height += 35;
      }
      if(this.isEdit === '1') {
        height2 += 40;
        height += 40;
      } else if(this.isEdit === '2') {
        height2 = 0;
        height += 0;
      }
      //界面
      let intHeight = 410 + height;
      this.dynamicHeight = intHeight.toString() + 'px';
      this.changePluginContainerHeight(height);
      //模块1
      let nodeHeight = 130 + height1;
      this.nodeDynamicHeight = nodeHeight.toString() + 'px';
      //模块2
      let cellHeight = 150 + height2;
      this.cellDynamicHeight = cellHeight.toString() + 'px';
      //模块3
      let checkHeight = 130 + height3;
      this.checkDynamicHeight = checkHeight.toString() + 'px';
    }
  },
}

</script>

<style scoped>

.wrap {
  font-size: 12px;
}

.letter {
  color: #606266;
  padding: 0 12px 0 0;
  font-size: 14px;
}

.subTitle {
  border-left: #1E9FFF solid 5px;
  padding-left: 5px;
  margin-left: 5px;
  font-size: 1rem;
  margin-bottom: 10px
}

>>> .el-upload--text {
  background-color: #FFFFFF;
}

.btn {
    height: 40px;
    border: none;
    position:fixed ;
    bottom: 0;
    right: 0;
    display: flex;
    justify-content: flex-end;
    margin-top: 0px;
}

</style>